/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kwikMart.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author WIL
 */
public class OperationResult implements Serializable {

    private boolean ok = true;
    private List<String> errors = new ArrayList<String>();
    public static final OperationResult operationOk = new OperationResult(true);
    private Object aditionalData;

    public String getFirst() {
        if (errors != null && !errors.isEmpty()) {
            return errors.get(0);
        }
        return "";
    }

    public OperationResult(boolean result) {
        this.ok = result;
    }

    public OperationResult(boolean result, List<String> errors) {
        this.ok = result;
        this.errors = errors;
    }

    public OperationResult(boolean result, String error) {
        this.ok = result;
        this.errors.add(error);
    }

    /**
     * @return the ok
     */
    public boolean isOk() {
        return ok;
    }

    /**
     * @param ok the ok to set
     */
    public void setOk(boolean result) {
        this.ok = result;
    }

    /**
     * @return the errors
     */
    public List<String> getErrors() {
        return errors;
    }

    /**
     * @param errors the errors to set
     */
    public void setErrors(List<String> errors) {
        this.errors = errors;
    }

    public void clear() {
        this.errors.clear();
        this.ok = true;
        this.aditionalData = null;
    }

    /**
     * @return the aditionalData
     */
    public Object getAditionalData() {
        return aditionalData;
    }

    /**
     * @param aditionalData the aditionalData to set
     */
    public void setAditionalData(Object aditionalData) {
        this.aditionalData = aditionalData;
    }
}
